package com.ruoyi.business.controller;

import com.ruoyi.business.domain.BusZdgz;
import com.ruoyi.business.domain.vo.BusZdgzSaveVO;
import com.ruoyi.business.service.IBusZdgzService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 重点工作Controller
 *
 * @author yaowei
 * @date 2021-07-01
 */
@Api(description = "重点工作管理")
@RestController
@RequestMapping("/business/zdgz")
public class BusZdgzController extends BaseController {
    @Autowired
    private IBusZdgzService busZdgzService;

    /**
     * 查询重点工作列表
     */
    @ApiOperation("重点工作列表")
    @GetMapping("/list")
    public TableDataInfo list(BusZdgz busZdgz) {
        startPage();
        List<BusZdgz> list = busZdgzService.selectBusZdgzList(busZdgz);
        return getDataTable(list);
    }

    /**
     * 导出重点工作列表
     */
    @Log(title = "重点工作", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusZdgz busZdgz) {
        List<BusZdgz> list = busZdgzService.selectBusZdgzList(busZdgz);
        ExcelUtil<BusZdgz> util = new ExcelUtil<BusZdgz>(BusZdgz.class);
        return util.exportExcel(list, "zdgz");
    }

    /**
     * 获取重点工作详细信息
     */
    @ApiOperation("根据ID查询总得工作详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(busZdgzService.selectBusZdgzById(id));
    }

    /**
     * 新增重点工作
     */
    @ApiOperation("重点工作新增/修改")
    @Log(title = "重点工作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusZdgzSaveVO busZdgzSaveVO) {
        Long id = busZdgzSaveVO.getId();
        if (id == null) {
            return toAjax(busZdgzService.insertBusZdgz(busZdgzSaveVO));
        } else {
            return toAjax(busZdgzService.updateBusZdgz(busZdgzSaveVO));
        }
    }

    /**
     * 修改重点工作
     */
    @PreAuthorize("@ss.hasPermi('business:zdgz:edit')")
    @Log(title = "重点工作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusZdgzSaveVO busZdgzSaveVO) {
        return toAjax(busZdgzService.updateBusZdgz(busZdgzSaveVO));
    }

    /**
     * 删除重点工作
     */
    @ApiOperation("删除重点工作")
    @Log(title = "重点工作", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(busZdgzService.deleteBusZdgzByIds(ids));
    }
}
